package Controller;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
*
* @author Nhóm java lớp PNV2T
* 				- Nguyễn Thị Lệ Đài
* 				- Nguyễn Chí Hướng
* 
* Contain all delete function of application
*/
public class Delete {
    private ConnectDB con = null;
    private ResultSet rs = null;
    /** Creates a new instance of Delete */
    public Delete() {
        try {
            con = new ConnectDB();
            con.open();
        } catch (Exception ex) {
            Logger.getLogger(ConnectDB.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public int XoaBangDiem(int MaSV,int MaMon){
        String sql = "Delete KetQuaHocTap Where MaSV = "+MaSV+" and MaMon = "+MaMon;
        con.setMode(ConnectDB.MODE_NORMAL);
        try {
            return con.doUpdate(sql);
        } catch (SQLException ex) {
            Logger.getLogger(ConnectDB.class.getName()).log(Level.SEVERE, null, ex);
        }
        return 0;
    }
    
    public int XoaBangDiemMonHoc(int MaMon){
        String sql = "Delete KetQuaHocTap Where MaMon = "+MaMon;
        con.setMode(ConnectDB.MODE_NORMAL);
        try {
            return con.doUpdate(sql);
        } catch (SQLException ex) {
            Logger.getLogger(ConnectDB.class.getName()).log(Level.SEVERE, null, ex);
        }
        return 0;
    }
    
    public int XoaBangDiemSinhVien(int MaSV){
        String sql = "Delete KetQuaHocTap Where MaSV = "+MaSV;
        con.setMode(ConnectDB.MODE_NORMAL);
        try {
            return con.doUpdate(sql);
        } catch (SQLException ex) {
            Logger.getLogger(ConnectDB.class.getName()).log(Level.SEVERE, null, ex);
        }
        return 0;
    }
    
    public int XoaMonHoc(int ID){
        String sql = "Delete MonHoc Where ID = "+ID;
        con.setMode(ConnectDB.MODE_NORMAL);
        try {
            return con.doUpdate(sql);
        } catch (SQLException ex) {
            Logger.getLogger(ConnectDB.class.getName()).log(Level.SEVERE, null, ex);
        }
        return 0;
    }
    
    public int XoaSinhVien(int ID){
        String sql = "Delete SinhVien Where ID = "+ID;
        con.setMode(ConnectDB.MODE_NORMAL);
        try {
            return con.doUpdate(sql);
        } catch (SQLException ex) {
            Logger.getLogger(ConnectDB.class.getName()).log(Level.SEVERE, null, ex);
        }
        return 0;
    }
    
    public int XoaLopHoc(int ID){
        String sql = "Delete LopHoc Where ID = "+ID;
        con.setMode(ConnectDB.MODE_NORMAL);
        try {
            return con.doUpdate(sql);
        } catch (SQLException ex) {
            Logger.getLogger(ConnectDB.class.getName()).log(Level.SEVERE, null, ex);
        }
        return 0;
    }
    
    public int XoaKhoaHoc(int ID){
        String sql = "Delete KhoaHoc Where ID = "+ID;
        con.setMode(ConnectDB.MODE_NORMAL);
        try {
            return con.doUpdate(sql);
        } catch (SQLException ex) {
            Logger.getLogger(ConnectDB.class.getName()).log(Level.SEVERE, null, ex);
        }
        return 0;
    }
    
    /**
     * Close connection
     */
    public void CloseData(){
        try {
            con.close();
        } catch (Exception ex) {
            Logger.getLogger(ConnectDB.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

	public int XoaTaiKhoan(int id) {
        String sql = "Delete Users Where ID = "+id;
        con.setMode(ConnectDB.MODE_NORMAL);
        try {
            return con.doUpdate(sql);
        } catch (SQLException ex) {
            Logger.getLogger(ConnectDB.class.getName()).log(Level.SEVERE, null, ex);
        }
        return 0;
    }
    
}
